home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / add-bevel.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  6.9 KB  |  195 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; add-bevel.scm version 1.04
  5. ; Time-stamp: <2004-02-09 17:07:06 simon>
  6. ;
  7. ; This program is free software; you can redistribute it and/or modify
  8. ; it under the terms of the GNU General Public License as published by
  9. ; the Free Software Foundation; either version 2 of the License, or
  10. ; (at your option) any later version.
  11. ;
  12. ; This program is distributed in the hope that it will be useful,
  13. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ; GNU General Public License for more details.
  16. ;
  17. ; You should have received a copy of the GNU General Public License
  18. ; along with this program; if not, write to the Free Software
  19. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. ;
  21. ; Copyright (C) 1997 Andrew Donkin  (ard@cs.waikato.ac.nz)
  22. ; Contains code from add-shadow.scm by Sven Neumann
  23. ; (neumanns@uni-duesseldorf.de) (thanks Sven).
  24. ;
  25. ; Adds a bevel to an image.  See http://www.cs.waikato.ac.nz/~ard/gimp/
  26. ;
  27. ; If there is a selection, it is bevelled.
  28. ; Otherwise if there is an alpha channel, the selection is taken from it
  29. ; and bevelled.
  30. ; Otherwise the whole image is bevelled.
  31. ;
  32. ; The selection is set on exit, so Select->Invert then Edit->Clear will
  33. ; leave a cut-out.  Then use Sven's add-shadow for that
  34. ; floating-bumpmapped-texture cliche.
  35.  
  36. ;
  37. ; 1.01: now works on offset layers.
  38. ; 1.02: has crop-pixel-border option to trim one pixel off each edge of the
  39. ;       bevelled image.  Bumpmapping leaves edge pixels unchanged, which
  40. ;       looks bad.  Oddly, this is not apparant in the GIMP - you have to
  41. ;       save the image and load it into another viewer.  First noticed in
  42. ;       Nutscrape.
  43. ;       Changed path (removed "filters/").
  44. ; 1.03: adds one-pixel border before bumpmapping, and removes it after.
  45. ;       Got rid of the crop-pixel-border option (no longer reqd).
  46. ; 1.04: Fixed undo handling, ensure that bumpmap is big enough,
  47. ;       (instead of resizing the image). Removed references to outdated
  48. ;       bumpmap plugin.     (Simon)
  49. ;
  50.  
  51. (define (script-fu-add-bevel img
  52.                              drawable
  53.                              thickness
  54.                              work-on-copy
  55.                              keep-bump-layer)
  56.  
  57.   (let* ((index 0)
  58.          (bevelling-whole-image FALSE)
  59.          (greyness 0)
  60.          (thickness (abs thickness))
  61.          (type (car (gimp-drawable-type-with-alpha drawable)))
  62.          (image (if (= work-on-copy TRUE) (car (gimp-image-duplicate img)) img))
  63.          (pic-layer (car (gimp-image-get-active-drawable image)))
  64.          (offsets (gimp-drawable-offsets pic-layer))
  65.          (width (car (gimp-drawable-width pic-layer)))
  66.          (height (car (gimp-drawable-height pic-layer)))
  67.  
  68.          ; Bumpmap has a one pixel border on each side
  69.          (bump-layer (car (gimp-layer-new image
  70.                                           (+ width 2)
  71.                                           (+ height 2)
  72.                                           GRAY
  73.                                           "Bumpmap"
  74.                                           100
  75.                                           NORMAL-MODE)))
  76.          (bevelling-whole-image TRUE)
  77.          (select))
  78.  
  79.     (gimp-context-push)
  80.  
  81.     ; disable undo on copy, start group otherwise
  82.     (if (= work-on-copy TRUE)
  83.       (gimp-image-undo-disable image)
  84.       (gimp-image-undo-group-start image)
  85.     )
  86.  
  87.     (gimp-image-add-layer image bump-layer 1)
  88.  
  89.     ; If the layer we're bevelling is offset from the image's origin, we
  90.     ; have to do the same to the bumpmap
  91.     (gimp-layer-set-offsets bump-layer (- (car offsets) 1)
  92.                                        (- (cadr offsets) 1))
  93.  
  94.     ;------------------------------------------------------------
  95.     ;
  96.     ; Set the selection to the area we want to bevel.
  97.     ;
  98.     (if (eq? 0 (car (gimp-selection-bounds image)))
  99.         (begin
  100.           (set! bevelling-whole-image TRUE) ; ...so we can restore things properly, and crop.
  101.           (if (car (gimp-drawable-has-alpha pic-layer))
  102.               (gimp-selection-layer-alpha pic-layer)
  103.               (gimp-selection-all image)
  104.           )
  105.         )
  106.      )
  107.  
  108.     ; Store it for later.
  109.     (set! select (car (gimp-selection-save image)))
  110.     ; Try to lose the jaggies
  111.     (gimp-selection-feather image 2)
  112.  
  113.     ;------------------------------------------------------------
  114.     ;
  115.     ; Initialise our bumpmap
  116.     ;
  117.     (gimp-context-set-background '(0 0 0))
  118.     (gimp-drawable-fill bump-layer BACKGROUND-FILL)
  119.  
  120.     (set! index 1)
  121.     (while (< index thickness)
  122.            (set! greyness (/ (* index 255) thickness))
  123.            (gimp-context-set-background (list greyness greyness greyness))
  124.            ;(gimp-selection-feather image 1) ;Stop the slopey jaggies?
  125.            (gimp-edit-bucket-fill bump-layer BG-BUCKET-FILL NORMAL-MODE
  126.                                   100 0 FALSE 0 0)
  127.            (gimp-selection-shrink image 1)
  128.            (set! index (+ index 1))
  129.     )
  130.     ; Now the white interior
  131.     (gimp-context-set-background '(255 255 255))
  132.     (gimp-edit-bucket-fill bump-layer BG-BUCKET-FILL NORMAL-MODE
  133.                            100 0 FALSE 0 0)
  134.  
  135.     ;------------------------------------------------------------
  136.     ;
  137.     ; Do the bump.
  138.     ;
  139.     (gimp-selection-none image)
  140.  
  141.     ; To further lessen jaggies?
  142.     ;(plug-in-gauss-rle 1 image bump-layer thickness TRUE TRUE)
  143.  
  144.  
  145.     ;
  146.     ; BUMPMAP INVOCATION:
  147.     ;
  148.     (plug-in-bump-map 1 image pic-layer bump-layer 125 45 3 0 0 0 0 TRUE FALSE 1)
  149.  
  150.     ;------------------------------------------------------------
  151.     ;
  152.     ; Restore things
  153.     ;
  154.     (if (= bevelling-whole-image TRUE)
  155.         (gimp-selection-none image)        ; No selection to start with
  156.         (gimp-selection-load select)
  157.     )
  158.     ; If they started with a selection, they can Select->Invert then
  159.     ; Edit->Clear for a cutout.
  160.  
  161.     ; clean up
  162.     (gimp-image-remove-channel image select)
  163.     (if (= keep-bump-layer TRUE)
  164.     (gimp-drawable-set-visible bump-layer 0)
  165.         (gimp-image-remove-layer image bump-layer))
  166.  
  167.     (gimp-image-set-active-layer image pic-layer)
  168.  
  169.     ; enable undo / end undo group
  170.     (if (= work-on-copy TRUE) 
  171.     (begin
  172.       (gimp-display-new image)
  173.       (gimp-image-undo-enable image))
  174.     (gimp-image-undo-group-end image))
  175.  
  176.     (gimp-displays-flush)
  177.  
  178.     (gimp-context-pop)))
  179.  
  180. (script-fu-register "script-fu-add-bevel"
  181.                     _"Add B_evel..."
  182.                     "Add a bevel to an image"
  183.                     "Andrew Donkin <ard@cs.waikato.ac.nz>"
  184.                     "Andrew Donkin"
  185.                     "1997/11/06"
  186.                     "RGB* GRAY*"
  187.                     SF-IMAGE       "Image"           0
  188.                     SF-DRAWABLE    "Drawable"        0
  189.                     SF-ADJUSTMENT _"Thickness"       '(5 0 30 1 2 0 0)
  190.                     SF-TOGGLE     _"Work on copy"    TRUE
  191.                     SF-TOGGLE     _"Keep bump layer" FALSE)
  192.  
  193. (script-fu-menu-register "script-fu-add-bevel"
  194.              _"<Image>/Script-Fu/Decor")
  195.